#! /bin/bash

laptop_host="moving-computer-of-doom"
remote_host="tiny-server-of-doom"

if [ $HOSTNAME = $laptop_host ]; then
	case "$SSH_ORIGINAL_COMMAND" in
		*\&*|*\|*|*\;*|*\>*|*\<*|*\!*)
		exit 1
		;;

		## This needs to be set in /etc/rsnapshot.conf rsync_long_args
		/usr/bin/rsync\ --server\ --sender*)
		sudo $SSH_ORIGINAL_COMMAND
		;;

		*)
		exit 1
		;;
	esac
elif [ $HOSTNAME = $remote_host ]; then
	case "$SSH_ORIGINAL_COMMAND" in
		*\&*|*\|*|*\;*|*\>*|*\<*|*\!*)
		exit 1
		;;

		mount*)
		sudo $SSH_ORIGINAL_COMMAND
		;;

		umount*)
		sudo $SSH_ORIGINAL_COMMAND
		;;

		cryptsetup\ luksOpen*)
		sudo $SSH_ORIGINAL_COMMAND
		;;

		cryptsetup\ luksClose*)
		sudo $SSH_ORIGINAL_COMMAND
		;;

		rmdir*)
		sudo $SSH_ORIGINAL_COMMAND
		;;

		mkdir*)
		sudo $SSH_ORIGINAL_COMMAND
		;;

		rsnapshot*)
		sudo $SSH_ORIGINAL_COMMAND
		;;

		*)
		exit 1
		;;
	esac
fi
